<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="h" uri="/syzg-html"%>
<%
	request.setAttribute("ctx", request.getContextPath());
%>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <link rel="stylesheet" href="${ctx }/base/js/ztree/css/demo.css" type="text/css">
  <link rel="stylesheet" href="${ctx }/base/js/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
  <script type="text/javascript" src="${ctx }/base/js/ztree/js/jquery.ztree.core.js"></script>
  <script type="text/javascript">
 	var setting = {
		data: {
			simpleData: {
				enable: true
			}
		},
		callback:{
		onClick:function(treeId, treeNode) {
                   var treeObj = $.fn.zTree.getZTreeObj(treeNode);  
                    var selectedNode = treeObj.getSelectedNodes()[0];
                    onClick(selectedNode.id); 
                    
                }  
		}
	};
	
	function onClick(id){
		if(id=='0'){
			content.document.location = "${ctx}/path/specialnews/listNewsinfo";
		} else {
			content.document.location = "${ctx}/path/specialnews/listNewsinfo?newsColId=" + id;
		}
	}

	$(document).ready(function(){
		var treeUrl = "${ctx }/path/specialnews/getNewsColumns";
		$.get(treeUrl,function(data){
			$.fn.zTree.init($("#newsColumns"), setting, data);
		});
	});
	
	function checkNews(val,name) {
		var originalSelected = $("#selectedNews").val();
		var originalSelectedName = $("#selectedNewsName").val();
		
		var selectedNews = $(val).val();
		var selectedNewsName = name;
		var newSelected = "";
		var newSelectedName = "";
		if($(val).prop("checked")){
			if(originalSelected !="") {
				newSelected = originalSelected + "," + selectedNews ;
				newSelectedName = originalSelectedName + "," + selectedNewsName;
			} else {
				newSelected = selectedNews;
				newSelectedName = selectedNewsName;
			}
		} else {
			var selectedArray = originalSelected.split(",");
			for(var count=0; count<selectedArray.length; count++){
				if(selectedNews == selectedArray[count]) {
					selectedArray[count] = null;
					break;
				}
			}
			for(var i=0; i<selectedArray.length; i++){
				if(selectedArray[i]) {
					newSelected +=  selectedArray[i] + ",";
				}
			}
			newSelected = newSelected.substring(0,newSelected.length-1);
			
			var selectedNameArray = originalSelectedName.split(",");
			for(var count=0; count<selectedNameArray.length; count++){
				if(selectedNewsName == selectedNameArray[count]) {
					selectedNameArray[count] = null;
					break;
				}
			}
			for(var i=0; i<selectedNameArray.length; i++){
				if(selectedNameArray[i]) {
					newSelectedName +=  selectedNameArray[i] + ",";
				}
			}
			newSelectedName = newSelectedName.substring(0,newSelectedName.length-1);
		}
		$("#selectedNews").prop("value", newSelected);
		$("#selectedNewsName").prop("value", newSelectedName);
	}
	
	function setNews() {
		$.post(setNewsUrl,$("#aeForm").serialize(),function(data){
			$('#selectNewsModal').modal("hide");
			$("#newsList").html(data);
		});
	}
  </script>
</head>
<body>
<div class="modal fade bs-example-modal-lg" id="selectNewsModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog modal-lg" role="document" style="width:850px;">
    <div class="modal-content">
      <div class="modal-header" style="padding: 8px;">
        <button type="button" class="close" onclick="javascript:$('#selectNewsModal').modal('hide');" aria-label="Close"></button>
        <h4 class="modal-title" id="myModalLabel" style="padding-bottom:0px">选择新闻</h4>
      </div>
      <div class="modal-body" id="modalCore">
        <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="1">
		  <tr>
		    <td width="220">
		      <ul id="newsColumns" class="ztree" style="margin-top: 0;height: 440px;border:0;"></ul>
		    </td>
		    <td>
		      <iframe width="100%" height="440px;" frameBorder="0" frameSpacing="0" src="${ctx}/path/specialnews/listNewsinfo" name="content" id="content"></iframe>
		    </td>
		  </tr>
		</table>
		<div id="myNewsDlg"></div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" onclick="javascript:$('#selectNewsModal').modal('hide');" style="font-size: 12px;">取消</button>
        <button type="button" class="btn btn-primary" onclick="setNews();" style="font-size: 12px;">选择</button>
      </div>
    </div>
  </div>
</div>
</body>
</html>

